package com.mostromas.ess.product.controller;

import com.mostromas.ess.entities.ProductBrand;
import com.mostromas.ess.entities.ProductColor;
import com.mostromas.ess.product.service.IProductColorService;
import com.mostromas.ess.util.base.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 商品颜色表-前端控制器
 */
@Api(value = "商品颜色管理接口",description = "商品颜色管理接口，提供颜色的增、删、改、查")
@RestController //所有方法都会返回json字符串进行相应
@RequestMapping("/color")
public class ProductColorController {

    @Autowired
    private IProductColorService productColorService;

    @PreAuthorize(("hasAuthority('color:search')"))
    @ApiOperation("获取所有的商品颜色信息接口")
    @GetMapping("/list")
    public Result list(){
        return Result.ok(productColorService.list());
    }

    @PreAuthorize(("hasAuthority('color:search')"))
    @ApiOperation("查询商品颜色详情接口")
    @ApiImplicitParam(name = "id",value = "颜色ID",required = true)
    @GetMapping("/{id}")
    public Result view(@PathVariable("id") String id){
        ProductColor color = productColorService.getById(id);
        return Result.ok(color);
    }

    @PreAuthorize(("hasAuthority('color:edit')"))
    @ApiOperation("修改商品颜色信息接口")
    @PutMapping
    public Result update(@RequestBody ProductColor color){
        productColorService.updateById(color);
        return Result.ok();
    }

    @PreAuthorize(("hasAuthority('color:add')"))
    @ApiOperation("新增商品颜色信息接口")
    @PostMapping
    public Result save(@RequestBody ProductColor color){
        productColorService.save(color);
        return Result.ok();
    }

    @PreAuthorize(("hasAuthority('color:delete')"))
    @ApiOperation("删除商品颜色信息接口")
    @ApiImplicitParam(name = "id",value = "颜色ID",required = true)
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") String id){
        productColorService.removeById(id);
        return Result.ok();
    }
}
